package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.backend.entity.BookletEntry;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 李月
 * @date 2022/5/2 19:06
 */
@Mapper
public interface BookletEntryMapper extends BaseMapper<BookletEntry> {
    /**
     * @param bookletId 单词本id
     * @return 单词本中条目数量
     */
    @Select("SELECT COUNT(entry_id) FROM tb_booklet_entry WHERE booklet_id=#{bookletId}")
    int getEntryCount(@Param("bookletId") int bookletId);

    /**
     * @param bookletId 单词本id
     * @return 单词本条目id
     */
    @Select("SELECT entry_id FROM tb_booklet_entry WHERE booklet_id=#{bookletId}")
    List<Integer> getEntryId(@Param("bookletId") int bookletId);

    /**
     * @param bookletId 单词本id
     * @param entryId 单词本条目id
     * @return 对应的单词本和条目
     */
    @Select("SELECT * FROM tb_booklet_entry WHERE booklet_id=#{bookletId} AND entry_id=#{entryId}")
    BookletEntry getBookletEntry(@Param("bookletId") int bookletId, @Param("entryId") int entryId);

    /**
     * @param bookletId 单词本id
     * @param entryId 单词本条目id
     * @return
     */
    @Delete("DELETE FROM tb_booklet_entry WHERE booklet_id=#{bookletId} AND entry_id=#{entryId}")
    void deleteBookletEntry(@Param("bookletId") int bookletId, @Param("entryId") int entryId);

    /**
     * @param bookletId 单词本id
     * @return
     */
    @Delete("DELETE FROM tb_booklet_entry WHERE booklet_id=#{bookletId}")
    void deleteBooklet(@Param("bookletId") int bookletId);

    /**
     * @param bookletId 单词本id
     * @return
     */
    @Select("SELECT COUNT(booklet_id) FROM tb_booklet_entry WHERE booklet_id=#{bookletId}")
    int getBookletCount(@Param("bookletId") int bookletId);
}
